<template>
  <div class="maintain">
    <Uploader :detail="detail" @on-success="sussessHandle" />
    <c-table-box ref="cTbaleBox" :index="false" hide-func :setting="false" :data="maintainList" :table-config="tableConfig">
      <el-table-column slot="before" type="expand" width="50">
        <template v-slot="{row}">
          <div style="padding:10px">
            <c-table-box :index="false" :data="row.shopAttachmentDTOList" hide-func :setting="false" :table-config="tableConfigAtt" />
          </div>
        </template>
      </el-table-column>
    </c-table-box>
    <ApproveLog :id="row.id" ref="appLog" />
  </div>
</template>
<script>
import Uploader from './components/Uploader'
import ApproveLog from '../components/ApproveLog'
import { getPictureInfo, getMaintains } from '@/api/shopDrawing'
export default {
  name: 'Maintain',
  components: {
    Uploader,
    ApproveLog
  },
  data() {
    return {
      tableConfig: {
        setting: [
          // {
          //   prop: '',
          //   label: '图纸名称'
          // },
          {
            prop: 'picBatchCode',
            label: '图纸批号'
          },
          // {
          //   prop: 'pictureName',
          //   label: '图纸名称'
          // },
          {
            prop: 'pictureNature',
            label: '图纸性质',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PICTURE_NATURE'
            }
          },
          {
            prop: 'isNeedApproval',
            label: '是否需要审批',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'constState',
            label: '门店建设状态',
            minWidth: 140,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'CONST_STATE'
            }
          },
          {
            prop: 'isValid',
            label: '是否有效',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: '',
            label: '操作',
            width: 140,
            render: (h, row) => {
              return h('el-button', {
                props: {
                  type: 'text'
                },
                on: {
                  click: () => {
                    this.row = row
                    this.$refs.appLog.openDialog()
                  }
                }
              }, '查看审批记录')
            }
          }
        ]
      },
      tableConfigAtt: {
        setting: [
          {
            prop: '',
            label: '图纸预览',
            width: 120,
            render: (h, row) => {
              return h('c-accessory', {
                props: {
                  src: row.attachmentUrl,
                  type: row.typeName,
                  width: '60px',
                  height: '60px'
                }
              })
            }
          },
          {
            prop: 'attachmentName',
            label: '图纸名称'
          },
          {
            prop: 'typeName',
            label: '附件类型'
          },
          {
            prop: 'createTime',
            label: '上传时间'
          },
          {
            prop: 'createBy',
            label: '上传人'
          },
          {
            prop: '',
            label: '操作',
            className: 'btn-green',
            render: (h, row) => {
              return h('el-button', {
                props: {
                  type: 'text'
                },
                on: {
                  click: () => {
                    this.fileDown(row)
                  }
                }
              }, '下载')
            }
          }
        ]
      },
      row: {},
      detail: {},
      maintainList: []
    }
  },
  created() {
    this.getDetail()
    this.getMaintainLog()
  },
  methods: {
    getDetail() {
      getPictureInfo(this.$route.query.id).then(res => {
        this.detail = res.data
      })
    },
    getMaintainLog() {
      getMaintains(this.$route.query.picTaskCode).then(res => {
        this.maintainList = res.data
      })
    },
    sussessHandle() {
      // this.getMaintainLog()
      this.$store.dispatch('views/goBack')
    },
    fileDown(row) {
      this.$downFile(row)
    },
    toLog(row) {
      // 查看日志
    }
  }
}
</script>
<style lang="scss" scoped>
.maintain{
  padding-top: 12px;
  .image{
    width: 48px;
    height: 48px;
  }
}
</style>
